<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<!--引入vue-->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<div id="app">
  <h2>总价格:{{totalPrice}}</h2>
</div>
<script>
  const app = new Vue({
    el: "#app",
    data:{
      message:"Hello zk I am Vue !",
      books:[
        {id:1,name: '书1',price:10},
        {id:2,name: '书2',price:15},
        {id:3,name: '书3',price:20},
        {id:4,name: '书4',price:30},
      ]
    },
    computed:{
      totalPrice(){
        //高级用法 filter/map/reduce
        let result=0
        for (let i=0;i<this.books.length;i++){
          result+=this.books[i].price
        }
        return result
      }
    }
  })
</script>
</body>
</html>
